package com.lzb.compressmaster.activity;

import android.os.Bundle;
import android.view.View;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.lzb.compressmaster.BaseAc;
import com.lzb.compressmaster.R;
import com.lzb.compressmaster.adapter.ImgListAdapter;
import com.lzb.compressmaster.adapter.ImgSortAdapter;
import com.lzb.compressmaster.databinding.ActivityImgSortBinding;
import com.lzb.compressmaster.utils.DragCallback;

import java.util.ArrayList;
import java.util.List;

public class ImgSortActivity extends BaseAc<ActivityImgSortBinding> implements View.OnClickListener {

    public static int type;
    private List<String> listPath = new ArrayList<>();
    private ImgSortAdapter sortAdapter;

    @Override
    protected int onCreate() {
        return R.layout.activity_img_sort;
    }

    @Override
    protected void initView() {
        mDataBinding.ivImgSortBack.setOnClickListener(view -> getOnBackPressedDispatcher().onBackPressed());

        mDataBinding.tvComplete.setOnClickListener(this);

        if (type == 0) {
            listPath.addAll(Img2PdfActivity.listPath);
        } else if (type == 1) {
            listPath.addAll(ImgSpliceActivity.listPath);
        }

        mDataBinding.rvPictureList.setLayoutManager(new LinearLayoutManager(mContext));
        sortAdapter = new ImgSortAdapter(listPath);
        mDataBinding.rvPictureList.setAdapter(sortAdapter);

        // 绑定拖动功能
        ItemTouchHelper touchHelper = new ItemTouchHelper(new DragCallback(sortAdapter));
        touchHelper.attachToRecyclerView(mDataBinding.rvPictureList);
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.tvComplete) {//完成
            if (type == 0) {
                Img2PdfActivity.listPath = listPath;
                finish();
            } else if (type == 1) {
                ImgSpliceActivity.listPath = listPath;
                finish();
            }
        }
    }

    @Override
    protected void initData() {

    }
}